﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;

namespace Minecraft_Armor_Stand_Creater.Util
{
    /// <summary>
    /// 程序配置模块
    /// </summary>
    class ProgramConfig : Singleton<ProgramConfig>
    {
        /// <summary>
        /// 输出结果存储
        /// </summary>
        public string Result;

        /// <summary> 
        /// 程序英汉显示切换 
        /// </summary>
        public bool _langCN = true;

        /// <summary> 
        /// 启动时是否开启引导 
        /// </summary>
        public bool Guidance = true;

        /// <summary>
        /// 当前引导状态
        /// </summary>
        public bool Guiding = true;

        /// <summary> 
        /// 默认颜色主题
        /// </summary>
        public string DefaultTheme = "Theme_Blue";

        public SortedList<string, string> ThemeList = new();

        static ProgramConfig()
        {
            //主题色加载
            Instance.ThemeList.Add("Theme_Blue", @"ResourceDictionary\Theme\Blue.xaml");
            Instance.ThemeList.Add("Theme_Green", @"ResourceDictionary\Theme\Green.xaml");
            Instance.ThemeList.Add("Theme_Purple", @"ResourceDictionary\Theme\Purple.xaml");
        }

        /// <summary>
        /// 终止外部进程
        /// </summary>
        /// <param name="processName">进程名</param>
        /// <param name="output">抛出错误内容</param>
        public static void KillProcess(string processName, bool output)
        {
            try
            {
                Process[] thisproc = Process.GetProcessesByName(processName);
                //thisproc.lendth:名字为进程总数
                if (thisproc.Length > 0)
                {
                    foreach (var item in thisproc)
                    {
                        //尝试关闭进程 释放资源,否则强制关闭  
                        if (!item.CloseMainWindow())
                            item.Kill();
                    }
                }
                else if (output)
                    MessageBox.Show($"进程{processName}关闭失败!");
            }
            catch (Exception ex)
            {
                MessageBox.Show($"结束进程{processName}时出错!\n{ex.Message}");
            }
        }
    }
}
